home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94a.txt / 000020_icon-group-sender _Fri Jan 14 06:24:08 1994.msg < prev    next >
Internet Message Format  |  1994-08-19  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Thu, 20 Jan 1994 09:07:54 MST
  2. Date: 14 Jan 94 06:24:08 GMT
  3. From: organpipe.uug.arizona.edu!CS.Arizona.EDU!not-for-mail@uunet.uu.net  (Nevin Liber)
  4. Organization: University of Arizona CS Department, Tucson AZ
  5. Subject: Re: Need help outputing to file
  6. Message-Id: <2h5dq8$h5m@caslon.CS.Arizona.EDU>
  7. References: <9401132354591.dligda.DLITE@delphi.com>
  8. Sender: icon-group-request@cs.arizona.edu
  9. To: icon-group@cs.arizona.edu
  10. Status: R
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12.  
  13. In article <9401132354591.dligda.DLITE@delphi.com>,
  14. David Ligda <dligda@delphi.com> wrote:
  15.  
  16. >procedure main(args)
  17. >       in := open(args[1]) | stop("Can't open input file")
  18. >       out := open(args[2], "w") | stop("cannot open output file")
  19.  
  20. This assigns "out" with a value of type "file".
  21.  
  22. >        while out := read(in) do {
  23.  
  24. Here is the bug.  This overwrites the old value of "out" with a value
  25. of type "string" (the first line of the input file).
  26.  
  27. >           write(out)
  28.  
  29. Since "out" is not of type "file", write() writses its output to the
  30. default stream &output.
  31.  
  32. One way to fix this is to use a different variable to keep the line of
  33. the file currently being worked on.  For example:
  34.  
  35.     while line := read(in) do {
  36.         write(out, line)
  37.     }
  38.  
  39. There are ways to do this as a one-liner, such as:
  40.  
  41.     while write(out, read(in))
  42.  
  43. But it might seem more confusing at first.
  44. -- 
  45.     Nevin ":-)" Liber    nevin@cs.arizona.edu    (602) 293-2799
  46.                                                   ^^^ (520) after 3/95
  47.